//
//  ContentView.swift
//  ImageFilter
//
//  Created by Amos on 2025/10/10.
//

import SwiftUI

struct ContentView: View {
    
    // 原始图片（确保 Assets.xcassets 中有此图片）
    let originalImage = UIImage(named: "test_image")!
    
    // 状态管理
    @State private var filterType: MetalImageView.FilterType = .original
    @State private var brightness: Float = 0.0 // 范围：-1.0 ~ 1.0

    var body: some View {
        VStack {
            // Metal 滤镜视图
            MetalImageView(
                image: originalImage,
                filterType: filterType,
                brightness: brightness
            )
            .frame(width: 300, height: 300)
            .border(Color.gray)
            
            // 滤镜切换按钮
            HStack(spacing: 20) {
                Button("原图") { filterType = .original }
                Button("灰度") { filterType = .grayscale }
                Button("亮度") { filterType = .brightness }
            }
            .padding()
            
            // 亮度滑块（仅亮度滤镜时显示）
            if filterType == .brightness {
                VStack {
                    Text("亮度: \(brightness, specifier: "%.1f")")
                    Slider(
                        value: $brightness,
                        in: -1.0...1.0,
                        step: 0.1
                    )
                    .padding(.horizontal, 40)
                }
            }
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
